import Vue from '@/main';
import axiosConfig from './axiosConfig';

export default {
  // 2.获取机床某时间段内的各个状态时间
  boardGetStateTime(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/getSumStateTime', params)
        .then(
          (res) => {
            if (res.msgCode == 0) {
              resolve(res.data);
            } else {
              Vue.$message.error(res.msgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 2.获取机床某时间段内的各个状态时间
  boardGetProduceRank(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/getProduceRank', params)
        .then(
          (res) => {
            if (res.msgCode == 0) {
              resolve(res.data);
            } else {
              Vue.$message.error(res.msgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  //
  // https://api.hzncc.cn/HncWeb/DayProduceSum.action?UserName=13867412431&startTime=2021-02-19&endTime=2021-02-25&compid=2
  boardDayProduceSum(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/DayProduceSum.action', params)
        .then(
          (res) => {
            if (res.MsgCode == 0) {
              resolve(res.Data);
            } else {
              Vue.$message.error(res.MsgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // https://api.hzncc.cn/HncWeb/HalfYearProduceSum.action?UserName=13867412431&startTime=2020-09-01&endTime=2021-02-26&compid=2
  boardMonthProduceSum(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/HalfYearProduceSum.action', params)
        .then(
          (res) => {
            if (res.MsgCode == 0) {
              resolve(res.Data);
            } else {
              Vue.$message.error(res.MsgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // https://api.hzncc.cn/HncWeb/MacAlarmStatisticByCompId.action?compId=2&startTime=2021-02-22&endTime=2021-03-01
  boardMacAlarmStatisticByCompId(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/MacAlarmStatisticByCompId.action', params)
        .then(
          (res) => {
            if (res.MsgCode == 0) {
              resolve(res.Data);
            } else {
              Vue.$message.error(res.MsgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 开机率
  // https://api.hzncc.cn/HncWeb/GroupOnlineRate.action?UserName=13867412431&startTime=2021-02-22&endTime=2021-02-28&compid=2
  // https://api.hzncc.cn/HncWeb/HalfYearGroupOnlineRate.action?UserName=13867412431&startTime=2020-10-01&endTime=2021-03-01&compid=2

  // 运行时间
  // https://api.hzncc.cn/HncWeb/GroupRunTime.action?UserName=13867412431&startTime=2021-02-22&endTime=2021-02-28&compid=21
  // https://api.hzncc.cn/HncWeb/HalfYearGroupRunTime.action?UserName=13867412431&startTime=2020-10-01&endTime=2021-03-01&compid=2

  // 故障时间
  // https://api.hzncc.cn/HncWeb/GroupAlarmTime.action?UserName=13867412431&startTime=2021-02-22&endTime=2021-02-28&compid=21
  // https://api.hzncc.cn/HncWeb/HalfYearGroupAlarmTime.action?UserName=13867412431&startTime=2020-10-01&endTime=2021-03-01&compid=2
  boardTimeState(url, params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet(url, params)
        .then(
          (res) => {
            if (res.MsgCode == 0) {
              resolve(res.Data);
            } else {
              Vue.$message.error(res.MsgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 获取任务列表
  boardGetAllTask(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/getAllTask', params)
        .then(
          (res) => {
            if (res.msgCode == 0) {
              resolve(res.data);
            } else {
              Vue.$message.error(res.msgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 获取班次日历数据
  boardGetAllDay(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/getAllDay', params)
        .then(
          (res) => {
            if (res.msgCode == 0) {
              resolve(res.data);
            } else {
              Vue.$message.error(res.msgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },

  // 根据日期获取当天的班次及打卡情况
  boardGetShiftByDay(params) {
    return new Promise(async (resolve, reject) => {
      axiosConfig
        .hncWebGet('/getShiftByDay', params)
        .then(
          (res) => {
            if (res.msgCode == 0) {
              resolve(res.data);
            } else {
              Vue.$message.error(res.msgDesc);
            }
          },
          (err) => {
            reject(err);
          }
        )
        .catch((error) => {
          reject(error);
        });
    });
  },
};
